(*
ledit ./mytop -I ../../octi-rawb/trunk 
#use "rawblas_test.ml";;
*)

open Octi_rawb;;

let sizeof_int = Bytes.info `Info_sizeof_int

let pv v =
  print_string "vector\n";
  List.iter (fun x -> print_string (" " ^ (string_of_float x) ^ "\n")) (Vector.Float64.to_list v);;

let vv = Vector.Float64.make_linspace 0 10 100.0 110.0;;


let _ = pv vv

let sum = Octi_rawblas.D.asum 3 (Vector.bytes vv) 1;;

let pointer_at v i =
  Vector.bytes (Vector.make_subvector v 0 i i)

let v4 = Vector.Float64.create 1 4
let _ = Vector.Float64.mset v4 [(1,0.1);(2,0.9);(3,10.2);(4,10.6)]
let a = pointer_at v4 1
let b = pointer_at v4 2
let c = pointer_at v4 3
let s = pointer_at v4 4
let _ = Octi_rawblas.D.rotg a b c s


let v9_1 = Vector.Float64.create 1 9
let bv9_1 = Vector.bytes v9_1
let v9_10 = Vector.Float64.create 1 9
let bv9_10 = Vector.bytes v9_10
let _ = Vector.Float64.fill_linspace v9_1 1.0 9.0
let _ = Vector.Float64.fill_linspace v9_10 10.0 90.0
let _ = Octi_rawblas.D.swap 2 bv9_1 2 bv9_10 3
let _ = 
  begin
    assert ((Vector.Float64.to_list v9_1)  = [10.; 2.; 40.; 4.; 5.; 6.; 7.; 8.; 9.]);
    assert ((Vector.Float64.to_list v9_10) = [1.; 20.; 30.; 3.; 50.; 60.; 70.; 80.; 90.]);
  end


let n = 2
let x = Vector.Float64.create 1 n
let _ = Vector.Float64.mset x [(1,1.0);(2,2.0)]
let xb = Vector.bytes x
let y = Vector.Float64.create 1 n
let _ = Vector.Float64.mset y [(1,11.0);(2,12.0)]
let yb = Vector.bytes y
let a = Vector.Float64.create 1 (n*n)
let _ = Vector.Float64.mset a [(1,100.0);(2,200.0);(3,300.0);(4,400.0)]
let ab = Vector.bytes a

let _ = print_string "\nDDOT\n"
let d = Octi_rawblas.D.dot n xb 1 yb 1
let _ = print_string ("dot = " ^ (string_of_float d) ^ "\n")

let _ = print_string "\nDGER\n"
let _ = Octi_rawblas.D.ger n n 1.0 xb 1 yb 1 ab 2
let _ = pv a


(*
let _ = print_string "\nDGESV\n"
let n = 2
let ma = Vector.Float64.create 1 (n*n)
let _ = Vector.Float64.mset ma [(1,1.0);(2,2.0);(3,-4.0);(4,2.0)]
let mab = Vector.bytes ma
let mb = Vector.Float64.create 1 (n*n)
let _ = Vector.Float64.mset mb [(1,1.0);(2,0.0);(3,0.0);(4,1.0)]
let mbb = Vector.bytes mb
let ipiv = Bytes.create (sizeof_int*n)
let infob = Bytes.create sizeof_int

let _ = pv ma
let _ = pv mb
let _ = Octi_rawblas.D.gesv n n mab n ipiv mbb n infob
let _ = pv ma
let _ = pv mb

let info = Bytes.C.Nativeint.get infob 0

let _ = print_string ("info = " ^ (string_of_int (Nativeint.to_int info)) ^ "\n")

let _ = print_string "\nDGESV non invertible\n"
let n = 2
let ma = Vector.Float64.create 1 (n*n)
let _ = Vector.Float64.mset ma [(1,1.0);(2,2.0);(3,-4.0);(4,-8.0)]
let mab = Vector.bytes ma
let mb = Vector.Float64.create 1 (n*n)
let _ = Vector.Float64.mset mb [(1,1.0);(2,0.0);(3,0.0);(4,1.0)]
let mbb = Vector.bytes mb
let ipiv = Bytes.create (sizeof_int*n)
let infob = Bytes.create sizeof_int

let _ = pv ma
let _ = Octi_rawblas.D.gesv n n mab n ipiv mbb n infob
let info = Bytes.C.Nativeint.get infob 0
let _ = print_string ("info = " ^ (string_of_int (Nativeint.to_int info)) ^ "\n")
*)
